package cn.baage.campus.utils;

import cn.baage.campus.constant.BaageConstant;
import cn.baage.campus.enums.ExceptionType;
import lombok.Data;

/**
 * @Description: 返回对象
 * @Author: 八阿哥
 * @url: baage.cn
 * @Version: 1.0
 **/
@Data
public class Result<T> {

    /** 响应码 **/
    private Integer code;

    /** 响应消息 **/
    private String message;

    /** 响应数据 **/
    private T data;


    /**
     * 成功响应
     */
    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.setCode(BaageConstant.SUCCESS_CODE);
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(BaageConstant.SUCCESS_CODE);
        result.setData(data);
        return result;
    }


    /**
     * 失败消息
     */
    public static <T> Result<T> fail() {
        Result<T> result = new Result<>();
        result.setCode(ExceptionType.BIZ_ERROR.getErrorCode());
        return result;
    }

    public static <T> Result<T> fail(String errorMessage) {
        Result<T> result = new Result<>();
        result.setCode(ExceptionType.BIZ_ERROR.getErrorCode());
        result.setMessage(errorMessage);
        return result;
    }

    public static <T> Result<T> fail(Integer errorCode, String errorMessage) {
        Result<T> result = new Result<>();
        result.setCode(errorCode);
        result.setMessage(errorMessage);
        return result;
    }

}
